home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3463 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: bristlecone.together.net!usenet
  2. From: John Wagner <jwag@together.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pointers HELP!!!!
  5. Date: Tue, 23 Jan 1996 19:29:35 +0000
  6. Organization: TGF Internet Services
  7. Message-ID: <3105371F.83F@together.net>
  8. References: <31055e1d.1020193@news.pi.se>
  9. NNTP-Posting-Host: vtr-npt102.ramp.together.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (Win95; I; 16bit)
  14.  
  15. Satai Delenn wrote:
  16.  
  17. > ////////////////////////////////////////////////////
  18. > class B
  19. > {
  20. > public:
  21. >         PFUNC m_callback;
  22. > public:
  23. >         B(PFUNC callback) {
  24. >                 m_callback = callback;
  25. >                 *m_callback(10);
  26. >         }
  27. >         ~B(){};
  28. > };
  29. > ////////////////////////////////////////////////////
  30. > I know this doesnt work, so please ne1 help me out here.
  31.  
  32. Yep, this doesn't work. A non-static member function accepts a "hidden" pointer to 
  33. the instance of it's class, called the "this" pointer. So the signature for the 
  34. callback in the class A is really: void callback(A *this, int error). Your 
  35. defination in the class B of the callback doesn't show a function with a parameter 
  36. list that accepts a class A (or an int for that matter).
  37.  
  38. You have two choices (as I see it). Make the callback function in class A static 
  39. (and fix the parameter list of callback in class B to accept an int), or pass a 
  40. pointer to a class A to the constructor of class B (and have an A* as a member of 
  41. class B) instead of a pointer to a function within a class A. 
  42.  
  43. To be brutally honest, it looks like a poor design and I would consider re-thinking 
  44. the problem.
  45.  
  46. Hope this helps,
  47. John
  48. jwag@together.net
  49.